package fulbiNet.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fulbiNet.execpcion.DAOExcepcion;
import fulbiNet.modelo.Cancha;
import fulbiNet.modelo.Dueno;
import fulbiNet.modelo.Horario;
import fulbiNet.modelo.Promocion;
import fulbiNet.modelo.Local;
import fulbiNet.negocio.CrearCanchaNegocio;
import fulbiNet.negocio.HorarioNegocio;

/**
 * Servlet implementation class CrearHorarioServLet
 */
@WebServlet("/CrearHorarioServLet")
public class CrearHorarioServLet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CrearHorarioServLet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		SimpleDateFormat format=new SimpleDateFormat("dd/MM/yyy HH:mm");
		//Negocio Crear Cliente Negocio -
		

		String idcancha  = request.getParameter("idcancha");
		String turnohorario = request.getParameter("turnohorario");
		String fecha  = request.getParameter("fecini");
		String horaini  = request.getParameter("horaini");
		String horafin = request.getParameter("horafin");
		String tarifa  = request.getParameter("tarifa");
		
		CrearCanchaNegocio neg = new CrearCanchaNegocio();			
		Cancha vo = new Cancha();
		vo.setCodigo(Integer.parseInt(idcancha)) ;

		HorarioNegocio negH = new HorarioNegocio();		
		Date horaInicioHorario= format.parse(horaini);
		Date horaFinHorario=format.parse(horafin);

		Horario horario=new Horario();
		horario.setDesdehora(new java.sql.Date(horaInicioHorario.getTime()));
		horario.setHastahora(new java.sql.Date(horaFinHorario.getTime()));
		horario.setDia2(fecha);
		
		
		try {
			negH.ingresarHorario(horario);		
			response.sendRedirect(request.getContextPath() + "/menu.jsp");
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
